package cn.net.xyan.blossom.security.dao

import cn.net.xyan.blossom.core.support.EasyJpaRepository
import cn.net.xyan.blossom.security.entity.SecurityPermission
import cn.net.xyan.blossom.security.entity.SecurityRole
import cn.net.xyan.blossom.security.entity.SecurityUserInfo
import org.springframework.data.jpa.repository.Query


interface SecurityUserInfoDao:EasyJpaRepository<SecurityUserInfo,String>{
    fun findByUsername(username:String?):SecurityUserInfo?
}

interface SecurityRoleDao:EasyJpaRepository<SecurityRole,String>{
    fun findByRole(role:String):SecurityRole?
}

interface SecurityPermissionDao:EasyJpaRepository<SecurityPermission,String>{
    fun findByName(name:String):SecurityPermission?

    @Query("select p from  SecurityUserInfo u join u.roles r join r.permissions p where u = ?1 and p = ?2")
    fun checkPermission(u:SecurityUserInfo,p:SecurityPermission):List<SecurityPermission>
}